package cn.itsource.org.service.impl;

import cn.itsource.org.domain.Department;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.query.EmployeeQuery;
import cn.itsource.org.service.IEmployeeService;
import cn.itsource.utli.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * 员工业务层实现类
 * @author Administrator
 */
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Employee> queryAll() {
        return employeeMapper.queryAll();
    }

    /**
     * 删除
     * @param id
     */
    @Override
    @Transactional
    public void delete(Long id) {
        employeeMapper.delete(id);
    }

    /**
     * 新增
     * @param employee
     */
    @Override
    @Transactional
    public void save(Employee employee) {
        employeeMapper.save(employee);
    }

    /**
     * 修改
     * @param employee
     */
    @Override
    @Transactional
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    /**
     * 查询单个数据
     * @param id
     * @return
     */
    @Override
    public Employee queryById(Long id) {
        return employeeMapper.queryById(id);
    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @Override
    public PageInfo<Employee> queryPage(EmployeeQuery query) {
        // 查询总条数
        Long count = employeeMapper.count(query);
        List<Employee> list = employeeMapper.queryDate(query);
        return new PageInfo<>(count,list);
    }

    /**
     * 批量删除
     * @param ids
     */
    @Override
    public void patchDel(Long[] ids) {
        employeeMapper.patchDel(ids);
    }
}
